package cn.jsprun.application;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class FlowerEggIpPool {
	private  Map<String,String>ipPoolMap =Collections.synchronizedMap(new TreeMap<String, String>());
	private static  FlowerEggIpPool instance=null;
	public static FlowerEggIpPool getInstance()
	{
		if(instance==null)instance=new FlowerEggIpPool();
		return instance;
	}
	public boolean isExsit(String ip,String flowerOrEgg){
		Date nowDate=new Date();
		String currentDate=new SimpleDateFormat ("yyyy-MM-dd").format(nowDate);	
		if(instance.ipPoolMap.containsKey(ip+flowerOrEgg)==true)return true;
		else {
			instance.ipPoolMap.put(ip+flowerOrEgg,currentDate);
			return false;
		}
	}
	public void cleanOldIp(){
		Date nowDate=new Date();
		String currentDate=new SimpleDateFormat ("yyyy-MM-dd").format(nowDate);	
		Iterator it= instance.ipPoolMap.entrySet().iterator();
		while(it.hasNext()){
			String oldDate=(String) it.next();
			if(oldDate.equalsIgnoreCase(currentDate)==false)it.remove();
		}
	}
}
